﻿namespace NKernel.Main
{
    using System;
    using System.Configuration;

    using Core;

    using log4net;
    using log4net.Config;

    class NKernelMain
    {
        #region Fields

        private readonly ILog logger = LogManager.GetLogger(typeof(NKernelMain));

        #endregion Fields

        #region Constructors

        NKernelMain()
        {
            XmlConfigurator.Configure(new System.IO.FileInfo(GetConfigFolder() + "log4net.config"));

            IKernel kernel = NKernelBuilder.Builder().MakeSynchronized()
                                    .GivePriority(new[] { "Consumer+" })
                                    .Build();

            kernel.Manage();

            logger.Debug("Press any key to continue . . . ");
            Console.ReadKey(true);
        }

        #endregion Constructors

        #region Methods

        public static void Main(string[] args)
        {
            new NKernelMain();
        }

        public string GetConfigFolder()
        {
            string configFolder = ConfigurationManager.AppSettings["ConfigFolder"];

            if (String.IsNullOrEmpty(configFolder))
            {
                return ".";
            }

            if (logger.IsDebugEnabled)
            {
                logger.Debug("Conf folder value: " + configFolder);
            }
            return configFolder;
        }

        #endregion Methods
    }
}